package com.xxx.modules.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {

    public static String getCurrentTime(){
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }

    public static String getCurrentDay(){
        return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    }

    // 获取两个时间相差分钟数
    public static long getTime(String oldTime,String newTime) throws ParseException {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long NTime =df.parse(newTime).getTime();
        //从对象中拿到时间
        long OTime = df.parse(oldTime).getTime();
        long diff=(NTime-OTime);
        return diff;
    }

    public static boolean compareTime(String time1,String time3) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Date date = format.parse(time1);
        Date date2 = format.parse(time3);
        long time = date.getTime();
        long time2 = date2.getTime();
        System.out.println("time大于time2：" + (time > time2));
        return time >time2;
    }
    public static void main(String[] args) throws ParseException {
//        long nd = 1000 * 24 * 60 * 60;
//        long nh = 1000 * 60 * 60;
//        long nm = 1000 * 60;
//        String time = "2022-02-18 12:31:39";
//        String time2 = "2022-02-19 12:38:39";
//        long time1 = TimeUtil.getTime(time, time2);
//        long min = time1 % nd % nh;
//        System.out.println(min);
        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date begin = dfs.parse("2022-03-02 11:30:24");

        Date end = dfs.parse("2022-03-03 13:31:40");

        long between = (end.getTime() - begin.getTime())/1000;

        long min = between/60;
        System.out.println(min);
    }
}
